package com.taptech.doufu.ui.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.widget.TextView;

import com.taptech.doufu.util.UIUtil;

/**
 * Created by lsy on 2015/9/10.
 */
public class TitleTextView extends TextView implements GestureDetector.OnGestureListener, GestureDetector.OnDoubleTapListener {
    Context mContext;
    GestureDetector gestureDetector;

    public TitleTextView(Context context) {
        super(context);
        initView(context);
    }

    public TitleTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }

    public TitleTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }

    public TitleTextView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        initView(context);
    }

    private void initView(Context context) {
        mContext = context;

    }

    public void enableGesture(boolean enable) {
        if (enable) {
            gestureDetector = new GestureDetector(mContext, this);
            gestureDetector.setOnDoubleTapListener(this);
        } else {
            gestureDetector = null;
        }
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        gestureDetector.onTouchEvent(event);
        return super.onTouchEvent(event);
    }

    @Override
    public boolean onSingleTapConfirmed(MotionEvent motionEvent) {
        return false;
    }

    @Override
    public boolean onDoubleTap(MotionEvent motionEvent) {
        UIUtil.toastMessage(mContext, "你竟然发现了这里可以双击。。。");
        return true;
    }

    @Override
    public boolean onDoubleTapEvent(MotionEvent motionEvent) {
        UIUtil.toastMessage(mContext, "你竟然发现了这里可以双击。。。");
        return true;
    }

    @Override
    public boolean onDown(MotionEvent motionEvent) {
        return true;
    }

    @Override
    public void onShowPress(MotionEvent motionEvent) {

    }

    @Override
    public boolean onSingleTapUp(MotionEvent motionEvent) {
        return false;
    }

    @Override
    public boolean onScroll(MotionEvent motionEvent, MotionEvent motionEvent1, float v, float v1) {
        return false;
    }

    @Override
    public void onLongPress(MotionEvent motionEvent) {

    }

    @Override
    public boolean onFling(MotionEvent motionEvent, MotionEvent motionEvent1, float v, float v1) {
        return false;
    }
}
